
#ifndef ENGINE_TASK_H
#define ENGINE_TASK_H


#include "base/types.h"
#include "base/result_codes.h"


namespace engine
{

/// \class Task
/// \brief Derive this class to generate app-specific tasks that can be managed by engine::Kernel
/// All Task objects have an associated priority, which can be used to specify the order of execution
/// of tasks in a task pool. 
/// The five events in the life of a Task are start, stop, update, suspend, and resume.
/// Thus a Task has the according 5 methods defined:
/// Start(), Update(), Stop(), OnSuspend(), OnResume().
/// In order to provide basic functionality, Task derivations \b must override the Start(), Update(), 
/// and Stop() methods. 
/// Additionaly, a task may choose to implement OnSuspend() and OnResume() to provide more granular
/// control over Task behavior.
class Task
{
public:
    Task() : priority_(0), can_kill_(false) {}
    explicit Task(uint64 priority) : priority_(priority), can_kill_(false) {}
    virtual ~Task(){}
    
    //Start, Update, Stop MUST be overriden in derived tasks
    //these are the main methods called in the game loop
    virtual int Start()=0;
    virtual int Update()=0;
    virtual int Stop()=0;

    //Additionally tasks MAY override OnSuspend, OnResume
    //These should be used to temporarily release important
    //resources until the task is resumed.
    virtual int OnSuspend(){return base::OK_OK;}
    virtual int OnResume(){return base::OK_OK;}


    //The following are simple getters and setters with no side effects.
    //no result codes necessary
    inline void SetPriority(const uint64 & priority) { priority_ = priority; }
    inline void SetCanKill(const bool & can_kill) { can_kill_ = can_kill; }
    inline const bool & GetCanKill() const { return can_kill_; }
    inline const uint64 & GetPriority() const { return priority_; }
private:        
    bool can_kill_;      //This task can be removed from task pool in the kernel   
    uint64 priority_;     //Used for sorting the task pool in the kernel

    DISALLOW_COPY_CONSTRUCTORS(Task);
};

}
#endif //end #ifndef ENGINE_TASK_H